import 'package:flutter/material.dart';

enum PageStatus { NO_RESULT, NO_MORE_RESULT, NO_SEARCH_RESULT, NO_NETWORK, ON_LOADING, LOAD_FAIL, TIME_OUT, NORMAL, NOT_FOUND }

Widget buildPageStatusView({PageStatus status = PageStatus.NORMAL, Widget? statusView, TextStyle? textStyle, required Widget child}) {
  textStyle = textStyle ?? TextStyle(fontSize: 16.0, color: Colors.black);
  statusView = statusView ??
      PageStatusView.full(
        textStyle: textStyle,
      );
  return Container(
    child: status == PageStatus.NORMAL ? child : statusView,
  );
}

class PageStatusView extends StatelessWidget {
  final String name;
  final TextStyle textStyle;
  final Widget? hintView;

  const PageStatusView({Key? key, String name = '数据', required this.textStyle, this.hintView})
      : this.name = name + '为空',
        super(key: key);

  const PageStatusView.full({Key? key, this.name = '页面数据为空', required this.textStyle, this.hintView}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return Container(
      padding: EdgeInsets.only(bottom: 10.0),
      alignment: Alignment.topCenter,
      child: Column(
        mainAxisSize: MainAxisSize.min,
        crossAxisAlignment: CrossAxisAlignment.center,
        children: [
          hintView ??
              Icon(
                Icons.hourglass_empty,
                size: 30.0,
              ),
          Text('$name', style: textStyle),
        ],
      ),
    );
  }
}
